package com.kenny.provider.controller;

import com.kenny.api.service.DemoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author Kenny Kam
 * @date 2021/1/8 16:20
 */
@RefreshScope
@RestController
@RequestMapping("/demo")
public class ConsumerController {

    @Autowired
    private DemoService demoService;

    @PostMapping("consumer")
    public void userService() {
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            String say = demoService.say();
            list.add(say);
        }
        long one = list.stream().filter(o -> StringUtils.contains(o, "111")).count();
        long two = list.stream().filter(o -> StringUtils.contains(o, "222")).count();
        long three = list.stream().filter(o -> StringUtils.contains(o, "333")).count();
        long fail = list.stream().filter(o -> StringUtils.contains(o, "失败")).count();

        System.out.printf("111 --》 %s 次\n", one);
        System.out.printf("222 --》 %s 次\n", two);
        System.out.printf("333 --》 %s 次\n", three);
        System.out.printf("fail --》 %s 次\n", fail);
    }
}
